/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JOrderTypeDialog.java
 *
 * Created on 2009-10-29, 9:51:03
 */

package cn.ekuma.epos.qkorder.dialog;

import cn.ekuma.data.dao.I_ParentNode;
import cn.ekuma.data.dao.bean.IKeyed;
import cn.ekuma.epos.bean.util.CustomerHelper;
import cn.ekuma.epos.businesslogic.RoleUtil;
import cn.ekuma.epos.datalogic.I_DataLogicCustomers;
import cn.ekuma.epos.datalogic.I_DataLogicERP;
import cn.ekuma.epos.inventory.JTimeStoreFinder;
import cn.ekuma.epos.order.JOrdersFinder;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.KeyBuilder;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.base.AppView;
import com.openbravo.bean.infobean.CustomerInfo;
import com.openbravo.bean.crm.CustomerAddress;
import com.openbravo.bean.erp.viewbean.FindOrdersInfo;
import com.openbravo.bean.AppUser;
import com.openbravo.bean.Customer;
import com.openbravo.bean.Location;
import com.openbravo.bean.erp.Order;
import com.openbravo.bean.erp.OrderType;
import com.openbravo.pos.bean.erp.OrderTypeCategoryExt;
import com.openbravo.bean.Product;
import com.openbravo.bean.erp.viewbean.TimeStore_V;
import com.openbravo.bean.infobean.UserInfo;
import com.openbravo.bean.shard.I_AddressEntity;
import com.openbravo.bean.shard.UserOrderTypePermission;
import com.openbravo.beans.JCalendarDialog;
import com.openbravo.pos.panels.JCustomerFinder;
import com.openbravo.pos.panels.JObjectListFinder;
import com.openbravo.pos.panels.JProductAttEdit;
import com.openbravo.pos.panels.JProductFinder;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.GroupLayout;
import javax.swing.SwingUtilities;
import org.jdesktop.swingx.JXTaskPane;
import org.jdesktop.swingx.JXTaskPaneContainer;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import javax.swing.JComboBox;

/**
 * 
 * @author Administrator
 */
public class JOrderTypeDialog extends javax.swing.JDialog {
	private boolean isOk;
	private Date createDate;
	private OrderType oType;
	private Location oLocateion;
	private Location oLocateion1;
	private I_DataLogicERP dlSales;
	private List<Location> locations;
	private List<OrderType> orderTypes;
	private List<OrderTypeCategoryExt> orderTypesCategories;
	private int orderType;
	private I_DataLogicCustomers dlCustomers;
	private CustomerInfo customerInfo;
	private String consultID;
	private ComboBoxValModel m_ReferencePersonListModel;
	private Product product;
	AppView app;
	private String productInstDescID;
	private JButton btnDateStart;
	private JLabel jLabel13;
	private JLabel jPriceTypeName;

	/**
	 * Creates new form JTicketChangeRateDialog
	 * 
	 * @wbp.parser.constructor
	 */
	public JOrderTypeDialog(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	/** Creates new form JProductLineKeyBoardEdit */
	private JOrderTypeDialog(java.awt.Dialog parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	public boolean isOk() {
		return isOk;
	}

	public int getOrderType() {
		return orderType;
	}

	public static JOrderTypeDialog getDialog(Component parent) {
		Window window = SwingUtilities.getWindowAncestor(parent);
		JOrderTypeDialog myMsg;
		if (window instanceof Frame) {
			myMsg = new JOrderTypeDialog((Frame) window, true);
		} else {
			myMsg = new JOrderTypeDialog((Dialog) window, true);
		}
		myMsg.applyComponentOrientation(parent.getComponentOrientation());
		return myMsg;
	}

	public void init(AppView app, CustomerInfo obj,I_DataLogicERP dlSales,I_DataLogicCustomers dlCustomers) throws BasicException {
		this.app = app;
		customerInfo=obj;
		this.dlSales = dlSales;
		this.dlCustomers = dlCustomers;

		isOk = false;
		locations = dlSales.list(Location.class);
		if (locations == null || locations.isEmpty()) {
			throw new BasicException(
					AppLocal.getIntString("message.noLocation"));
		}

		for (int i = 0; i < locations.size(); i++) {
			jLocation.addItem(locations.get(i));
		}
		jLocation.setSelectedIndex(0);

		jLocation1.addItem(null);
		for (Location item : locations) {
			jLocation1.addItem(item);
		}

		orderTypes = dlSales.list(OrderType.class);
		List<OrderType> grantedOrderTypes = new ArrayList<OrderType>();
		if (orderTypes != null) {
			for (OrderType t : orderTypes)
				if (RoleUtil
						.hasOrderTypePermission(
								(AppUser) app.getAppUserView().getUser(),
								t.getId(),
								RoleUtil.getLocalePermissionName(UserOrderTypePermission.ORDERTYPEEVENT_Create)))
					grantedOrderTypes.add(t);
		}
		orderTypes = grantedOrderTypes;
		if (orderTypes.isEmpty()) {
			throw new BasicException(
					AppLocal.getIntString("message.noOrderType"));
		}

		orderTypesCategories = dlSales.list(OrderTypeCategoryExt.class);
		Map<String, JXTaskPane> categoryPanelMap = new HashMap<String, JXTaskPane>();
		JXTaskPane defPanel = new JXTaskPane();
		defPanel.setTitle("default");
		categoryPanelMap.put("default", defPanel);
		JXTaskPane catePanel = null;
		if (orderTypesCategories != null) {
			for (OrderTypeCategoryExt item : orderTypesCategories) {
				catePanel = new JXTaskPane();
				catePanel.setTitle(item.getName());
				categoryPanelMap.put(item.getID(), catePanel);
			}
		}

		for (OrderType item : orderTypes) {
			catePanel = categoryPanelMap.get(item.getCategoryid());
			if (catePanel == null)
				catePanel = categoryPanelMap.get("default");
			catePanel.add(new OrderTypeSelectedAction(item));
		}

		for (JXTaskPane panel : categoryPanelMap.values()) {
			if (panel.getContentPane().getComponentCount() > 0)
				jXTaskPaneContainer1.add(panel);
		}

		List catlist = null;
		try {
			catlist = dlSales.list(UserInfo.class);
			;
		} catch (BasicException ex) {
			new MessageInf(ex).show(this);
		}
		catlist.add(0, null);
		m_ReferencePersonListModel = new ComboBoxValModel(catlist);
		jcboUser.setModel(m_ReferencePersonListModel);

		oType = orderTypes.get(0);
		consultID = null;
		orderType = Order.ORDERBEARING_NORMAL;
		getRootPane().setDefaultButton(m_jButtonOK);
		reflushOrderTypeState();

		createDate = new Date();
		jTxtStartDate.setText(Formats.TIMESTAMP.formatValue(this.createDate));
		
		cbDeliverType.addItem(null);
		cbDeliverType.addItem(AppLocal
				.getIntString("list.DeliverType.door-to-door"));
		cbDeliverType.addItem(AppLocal
				.getIntString("list.DeliverType.PickUpByCustomer"));
		cbDeliverType.addItem(AppLocal
				.getIntString("list.DeliverType.CashOnDelivery"));
		cbDeliverType.addItem(AppLocal
				.getIntString("list.DeliverType.Express"));
		
		if(customerInfo!=null){
			jCustomerName.setText(CustomerHelper.printName(customerInfo));
			try {
				  setCustomerAddr((I_AddressEntity) dlSales.findByStringId(Customer.class,customerInfo.getId()));
			 } catch (BasicException e) {
				 e.printStackTrace();
			}
		}
	}

	public Location getoLocateion() {
		return oLocateion;
	}

	public Location getoLocateion1() {
		return oLocateion1;
	}

	public OrderType getoType() {
		return oType;
	}

	public CustomerInfo getCustomerInfo() {
		return customerInfo;
	}

	public String getConsultID() {
		return consultID;
	}
	
	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	private void initComponents() {
		jTextField1 = new javax.swing.JTextField();
		jPanel11 = new javax.swing.JPanel();
		jPanel1 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		jOrderTypeName = new javax.swing.JTextField();
		jTxtStartDate = new javax.swing.JTextField();
		btnDateStart = new javax.swing.JButton();
		jLabel13 = new javax.swing.JLabel();
		jReverse = new javax.swing.JCheckBox();
		jReverse.setEnabled(false);
		jPanel6 = new javax.swing.JPanel();
		jCustomer = new javax.swing.JButton();
		jCustomerName = new javax.swing.JLabel();
		jPanel4 = new javax.swing.JPanel();
		jChangePrice = new javax.swing.JCheckBox();
		jPriceTypeName = new javax.swing.JLabel();
		jPanel10 = new javax.swing.JPanel();
		jFundNoChange = new javax.swing.JRadioButton();
		jFundIn = new javax.swing.JRadioButton();
		jFundOut = new javax.swing.JRadioButton();
		jPanel2 = new javax.swing.JPanel();
		jPanel2.setPreferredSize(new Dimension(10, 100));
		jLabel2 = new javax.swing.JLabel();
		jLocation = new javax.swing.JComboBox();
		jLabel3 = new javax.swing.JLabel();
		jLocation1 = new javax.swing.JComboBox();
		jLocation_type = new javax.swing.JTextField();
		jLocation1_type = new javax.swing.JTextField();
		jLabel8 = new javax.swing.JLabel();
		jLabel9 = new javax.swing.JLabel();
		jPanel3 = new javax.swing.JPanel();
		jLabel10 = new javax.swing.JLabel();
		jcboUser = new javax.swing.JComboBox();
		jPanel9 = new javax.swing.JPanel();
		jLabel4 = new javax.swing.JLabel();
		jLabel5 = new javax.swing.JLabel();
		jSearchTimeStore = new javax.swing.JButton();
		jLabel6 = new javax.swing.JLabel();
		jLabel7 = new javax.swing.JLabel();
		jSearchOrder = new javax.swing.JButton();
		jPanel8 = new javax.swing.JPanel();
		jLabel11 = new javax.swing.JLabel();
		jproduct = new javax.swing.JTextField();
		jEditProduct = new javax.swing.JButton();
		jEditAttributes = new javax.swing.JButton();
		jattributes = new javax.swing.JTextField();
		jLabel12 = new javax.swing.JLabel();
		jPanel7 = new javax.swing.JPanel();
		m_jButtonOK = new javax.swing.JButton();
		m_jButtonCancel = new javax.swing.JButton();
		jPanel12 = new javax.swing.JPanel();
		jXTaskPaneContainer1 = new org.jdesktop.swingx.JXTaskPaneContainer();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jPanel11.setLayout(new javax.swing.BoxLayout(jPanel11,
				javax.swing.BoxLayout.PAGE_AXIS));

		jLabel1.setText(AppLocal.getIntString("label.ordertype.name")); // NOI18N

		jOrderTypeName.setEditable(false);

		jTxtStartDate.setMinimumSize(new java.awt.Dimension(6, 15));
		jTxtStartDate.setPreferredSize(new java.awt.Dimension(150, 22));

		btnDateStart.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/com/openbravo/images/date.png"))); // NOI18N
		btnDateStart.setFocusable(false);
		btnDateStart
				.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		btnDateStart.setPreferredSize(new java.awt.Dimension(55, 25));
		btnDateStart.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		btnDateStart.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnDateStartActionPerformed(evt);
			}
		});

		jLabel13.setText(AppLocal.getIntString("Label.StartDate")); // NOI18N
		
		jReverse.setText(AppLocal.getIntString("label.orderbearing.reverse")); // NOI18N
		jReverse.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jReverseActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout gl_jPanel1 = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(gl_jPanel1);
		gl_jPanel1
				.setHorizontalGroup(gl_jPanel1
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel1
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_jPanel1
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																false)
														.addComponent(
																jLabel13,
																javax.swing.GroupLayout.Alignment.TRAILING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.addComponent(
																jLabel1,
																javax.swing.GroupLayout.Alignment.TRAILING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																159,
																Short.MAX_VALUE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												gl_jPanel1
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																false)
														.addComponent(
																jOrderTypeName,
																javax.swing.GroupLayout.Alignment.TRAILING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																179,
																Short.MAX_VALUE)
														.addComponent(
																jTxtStartDate,
																javax.swing.GroupLayout.Alignment.TRAILING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE))
										.addGroup(
												gl_jPanel1
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																gl_jPanel1
																		.createSequentialGroup()
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				btnDateStart,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				47,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_jPanel1
																		.createSequentialGroup()
																		.addGap(34,
																				34,
																				34)
																		.addComponent(
																				jReverse,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				93,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(66, Short.MAX_VALUE)));
		gl_jPanel1
				.setVerticalGroup(gl_jPanel1
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel1
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_jPanel1
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel1)
														.addComponent(
																jOrderTypeName,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jReverse))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addGroup(
												gl_jPanel1
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																gl_jPanel1
																		.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																		.addComponent(
																				jLabel13)
																		.addComponent(
																				jTxtStartDate,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				25,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addComponent(
																btnDateStart,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																23,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(15, Short.MAX_VALUE)));

		jPanel11.add(jPanel1);

		jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(AppLocal
				.getIntString("label.customer"))); // NOI18N

		jCustomer.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/com/openbravo/images/edit_group.png"))); // NOI18N
		jCustomer.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jCustomerActionPerformed(evt);
			}
		});
		
		customerAddr = new JTextField();
		customerAddr.setColumns(10);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jCustomerAddrActionPerformed(e);
			}
		});
		btnNewButton.setIcon(new ImageIcon(JOrderTypeDialog.class.getResource("/com/openbravo/images/appointment.png")));

		javax.swing.GroupLayout gl_jPanel6 = new javax.swing.GroupLayout(
				jPanel6);
		gl_jPanel6.setHorizontalGroup(
			gl_jPanel6.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_jPanel6.createSequentialGroup()
					.addGap(23)
					.addGroup(gl_jPanel6.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_jPanel6.createSequentialGroup()
							.addComponent(customerAddr, GroupLayout.PREFERRED_SIZE, 386, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(btnNewButton))
						.addGroup(gl_jPanel6.createSequentialGroup()
							.addComponent(jCustomerName, GroupLayout.PREFERRED_SIZE, 395, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(jCustomer, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(17, Short.MAX_VALUE))
		);
		gl_jPanel6.setVerticalGroup(
			gl_jPanel6.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_jPanel6.createSequentialGroup()
					.addGroup(gl_jPanel6.createParallelGroup(Alignment.LEADING)
						.addComponent(jCustomerName, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
						.addComponent(jCustomer))
					.addPreferredGap(ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
					.addGroup(gl_jPanel6.createParallelGroup(Alignment.BASELINE)
						.addComponent(customerAddr, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnNewButton)))
		);
		gl_jPanel6.linkSize(SwingConstants.VERTICAL, new Component[] {jCustomer, jCustomerName});
		jPanel6.setLayout(gl_jPanel6);

		jPanel11.add(jPanel6);

		jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(AppLocal
				.getIntString("label.ordertype.pricttype"))); // NOI18N
		jPanel4.setEnabled(false);

		jChangePrice.setText(AppLocal
				.getIntString("label.ordertype.changePrice")); // NOI18N
		jChangePrice.setEnabled(false);

		jPriceTypeName.setText("jLabel14");

		javax.swing.GroupLayout gl_jPanel4 = new javax.swing.GroupLayout(
				jPanel4);
		jPanel4.setLayout(gl_jPanel4);
		gl_jPanel4
				.setHorizontalGroup(gl_jPanel4
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel4
										.createSequentialGroup()
										.addGap(48, 48, 48)
										.addComponent(
												jPriceTypeName,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												340,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jChangePrice,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												144,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		gl_jPanel4.setVerticalGroup(gl_jPanel4.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				gl_jPanel4
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.BASELINE)
						.addComponent(jChangePrice)
						.addComponent(jPriceTypeName)));

		jPanel11.add(jPanel4);

		jPanel10.setBorder(javax.swing.BorderFactory
				.createTitledBorder(AppLocal
						.getIntString("label.ordertype.fundtype"))); // NOI18N

		jFundNoChange.setText(AppLocal
				.getIntString("list.OrderType.FUNDTYPE_NoChange")); // NOI18N
		jFundNoChange.setEnabled(false);
		jFundNoChange.setMaximumSize(new java.awt.Dimension(100, 23));

		jFundIn.setText(AppLocal.getIntString("list.OrderType.FUNDTYPE_In")); // NOI18N
		jFundIn.setEnabled(false);
		jFundIn.setMaximumSize(new java.awt.Dimension(100, 23));
		jFundIn.setMinimumSize(new java.awt.Dimension(50, 23));
		jFundIn.setPreferredSize(new java.awt.Dimension(60, 23));

		jFundOut.setText(AppLocal.getIntString("list.OrderType.FUNDTYPE_Out")); // NOI18N
		jFundOut.setEnabled(false);
		jFundOut.setMaximumSize(new java.awt.Dimension(100, 23));

		javax.swing.GroupLayout gl_jPanel10 = new javax.swing.GroupLayout(
				jPanel10);
		jPanel10.setLayout(gl_jPanel10);
		gl_jPanel10
				.setHorizontalGroup(gl_jPanel10
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel10
										.createSequentialGroup()
										.addGap(36, 36, 36)
										.addComponent(
												jFundNoChange,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												143,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(
												jFundIn,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												149,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jFundOut,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												151,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(38, Short.MAX_VALUE)));

		gl_jPanel10.linkSize(javax.swing.SwingConstants.HORIZONTAL,
				new java.awt.Component[] { jFundIn, jFundNoChange, jFundOut });

		gl_jPanel10
				.setVerticalGroup(gl_jPanel10
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel10
										.createSequentialGroup()
										.addGroup(
												gl_jPanel10
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																jFundNoChange,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																jFundOut,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																jFundIn,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap()));

		jPanel11.add(jPanel10);

		jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(AppLocal
				.getIntString("label.warehouse"))); // NOI18N

		jLabel2.setText(AppLocal.getIntString("label.warehouse")); // NOI18N

		jLocation.setEnabled(false);

		jLabel3.setText(AppLocal.getIntString("label.warehouse")); // NOI18N

		jLocation1.setEnabled(false);

		jLocation_type.setEditable(false);

		jLocation1_type.setEditable(false);

		jLabel8.setText(AppLocal.getIntString("label.ordertype.storetype")); // NOI18N

		jLabel9.setText(AppLocal.getIntString("label.ordertype.storetype")); // NOI18N
		
		label = new JLabel("出入方式");
		
		cbDeliverTypeDesc = new JTextField();
		cbDeliverTypeDesc.setColumns(10);
		
		cbDeliverType = new JComboBox();

		javax.swing.GroupLayout gl_jPanel2 = new javax.swing.GroupLayout(
				jPanel2);
		gl_jPanel2.setHorizontalGroup(
			gl_jPanel2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_jPanel2.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_jPanel2.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_jPanel2.createSequentialGroup()
							.addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(jLocation, GroupLayout.PREFERRED_SIZE, 214, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(jLabel9, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(jLocation_type, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_jPanel2.createSequentialGroup()
							.addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_jPanel2.createParallelGroup(Alignment.LEADING, false)
								.addGroup(gl_jPanel2.createSequentialGroup()
									.addComponent(label, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(cbDeliverType, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addGap(18)
									.addComponent(cbDeliverTypeDesc, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_jPanel2.createSequentialGroup()
									.addComponent(jLocation1, GroupLayout.PREFERRED_SIZE, 214, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(jLabel8, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(jLocation1_type, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)))))
					.addGap(72))
		);
		gl_jPanel2.setVerticalGroup(
			gl_jPanel2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_jPanel2.createSequentialGroup()
					.addGroup(gl_jPanel2.createParallelGroup(Alignment.BASELINE)
						.addComponent(jLabel2)
						.addComponent(jLocation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(jLocation_type, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(jLabel9))
					.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGroup(gl_jPanel2.createParallelGroup(Alignment.BASELINE)
						.addComponent(label)
						.addComponent(cbDeliverTypeDesc, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(cbDeliverType, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_jPanel2.createParallelGroup(Alignment.BASELINE)
						.addComponent(jLabel3)
						.addComponent(jLocation1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(jLocation1_type, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(jLabel8)))
		);
		jPanel2.setLayout(gl_jPanel2);

		jPanel11.add(jPanel2);

		java.util.ResourceBundle bundle = java.util.ResourceBundle
				.getBundle("pos_messages"); // NOI18N
		jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle
				.getString("label.referncePerson"))); // NOI18N

		jLabel10.setText(AppLocal.getIntString("label.user")); // NOI18N

		javax.swing.GroupLayout gl_jPanel3 = new javax.swing.GroupLayout(
				jPanel3);
		jPanel3.setLayout(gl_jPanel3);
		gl_jPanel3
				.setHorizontalGroup(gl_jPanel3
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel3
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												jLabel10,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												159,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jcboUser,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												240,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(116, Short.MAX_VALUE)));
		gl_jPanel3.setVerticalGroup(gl_jPanel3.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				gl_jPanel3
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.BASELINE)
						.addComponent(jLabel10)
						.addComponent(jcboUser,
								javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.PREFERRED_SIZE)));

		jPanel11.add(jPanel3);

		jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(AppLocal
				.getIntString("label.ordertype.consulttype"))); // NOI18N

		jLabel4.setText(AppLocal
				.getIntString("list.OrderType.CONSULTTYPE_Order")); // NOI18N

		jLabel5.setPreferredSize(new java.awt.Dimension(0, 20));

		jSearchTimeStore.setIcon(new javax.swing.ImageIcon(getClass()
				.getResource("/com/openbravo/images/search.png"))); // NOI18N
		jSearchTimeStore.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jSearchTimeStoreActionPerformed(evt);
			}
		});

		jLabel6.setText(AppLocal
				.getIntString("list.OrderType.CONSULTTYPE_TimeSliceStore")); // NOI18N

		jLabel7.setPreferredSize(new java.awt.Dimension(0, 20));

		jSearchOrder.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/com/openbravo/images/search.png"))); // NOI18N
		jSearchOrder.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jSearchOrderActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout gl_jPanel9 = new javax.swing.GroupLayout(
				jPanel9);
		jPanel9.setLayout(gl_jPanel9);
		gl_jPanel9
				.setHorizontalGroup(gl_jPanel9
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								gl_jPanel9
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_jPanel9
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																false)
														.addComponent(
																jLabel6,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.addComponent(
																jLabel4,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																129,
																Short.MAX_VALUE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												gl_jPanel9
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																false)
														.addComponent(
																jLabel7,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.addComponent(
																jLabel5,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																279,
																Short.MAX_VALUE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												gl_jPanel9
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																false)
														.addComponent(
																jSearchOrder,
																0, 0,
																Short.MAX_VALUE)
														.addComponent(
																jSearchTimeStore,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																36,
																Short.MAX_VALUE))
										.addContainerGap(65, Short.MAX_VALUE)));
		gl_jPanel9
				.setVerticalGroup(gl_jPanel9
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel9
										.createSequentialGroup()
										.addGroup(
												gl_jPanel9
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel4)
														.addComponent(
																jLabel5,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																jSearchOrder,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																25,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												gl_jPanel9
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel6)
														.addComponent(
																jLabel7,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																jSearchTimeStore))));

		jPanel11.add(jPanel9);

		jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(AppLocal
				.getIntString("label.productConsult"))); // NOI18N

		jLabel11.setText(AppLocal.getIntString("label.stockproduct")); // NOI18N

		jproduct.setEditable(false);

		jEditProduct.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/com/openbravo/images/search.png"))); // NOI18N
		jEditProduct.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jEditProductActionPerformed(evt);
			}
		});

		jEditAttributes.setIcon(new javax.swing.ImageIcon(getClass()
				.getResource("/com/openbravo/images/colorize16.png"))); // NOI18N
		jEditAttributes.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jEditAttributesActionPerformed(evt);
			}
		});

		jattributes.setEditable(false);

		jLabel12.setText(AppLocal.getIntString("label.attributes")); // NOI18N

		javax.swing.GroupLayout gl_jPanel8 = new javax.swing.GroupLayout(
				jPanel8);
		jPanel8.setLayout(gl_jPanel8);
		gl_jPanel8
				.setHorizontalGroup(gl_jPanel8
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel8
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												gl_jPanel8
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																gl_jPanel8
																		.createSequentialGroup()
																		.addComponent(
																				jLabel11,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				150,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				jproduct,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				250,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addGap(10,
																				10,
																				10)
																		.addComponent(
																				jEditProduct,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				40,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_jPanel8
																		.createSequentialGroup()
																		.addComponent(
																				jLabel12,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				150,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				jattributes,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				250,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				jEditAttributes,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				40,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addContainerGap(65, Short.MAX_VALUE)));
		gl_jPanel8
				.setVerticalGroup(gl_jPanel8
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								gl_jPanel8
										.createSequentialGroup()
										.addGroup(
												gl_jPanel8
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel11)
														.addComponent(
																jproduct,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																jEditProduct))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												gl_jPanel8
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																jEditAttributes)
														.addGroup(
																gl_jPanel8
																		.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.BASELINE)
																		.addComponent(
																				jattributes,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addComponent(
																				jLabel12)))));

		gl_jPanel8.linkSize(javax.swing.SwingConstants.VERTICAL,
				new java.awt.Component[] { jLabel11, jproduct });

		jPanel11.add(jPanel8);

		m_jButtonOK.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/com/openbravo/images/button_ok.png"))); // NOI18N
		m_jButtonOK.setText(AppLocal.getIntString("Button.OK")); // NOI18N
		m_jButtonOK.setFocusPainted(false);
		m_jButtonOK.setFocusable(false);
		m_jButtonOK.setMargin(new java.awt.Insets(8, 16, 8, 16));
		m_jButtonOK.setRequestFocusEnabled(false);
		m_jButtonOK.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				m_jButtonOKActionPerformed(evt);
			}
		});

		m_jButtonCancel.setIcon(new javax.swing.ImageIcon(getClass()
				.getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N
		m_jButtonCancel.setText(AppLocal.getIntString("Button.Cancel")); // NOI18N
		m_jButtonCancel.setFocusPainted(false);
		m_jButtonCancel.setFocusable(false);
		m_jButtonCancel.setMargin(new java.awt.Insets(8, 16, 8, 16));
		m_jButtonCancel.setRequestFocusEnabled(false);
		m_jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				m_jButtonCancelActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout gl_jPanel7 = new javax.swing.GroupLayout(
				jPanel7);
		jPanel7.setLayout(gl_jPanel7);
		gl_jPanel7
				.setHorizontalGroup(gl_jPanel7
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								gl_jPanel7
										.createSequentialGroup()
										.addContainerGap(338, Short.MAX_VALUE)
										.addComponent(m_jButtonOK)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(m_jButtonCancel)
										.addGap(25, 25, 25)));
		gl_jPanel7.setVerticalGroup(gl_jPanel7
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(m_jButtonOK,
						javax.swing.GroupLayout.PREFERRED_SIZE, 32,
						javax.swing.GroupLayout.PREFERRED_SIZE)
				.addComponent(m_jButtonCancel, 0, 0, Short.MAX_VALUE));

		jPanel11.add(jPanel7);

		getContentPane().add(jPanel11, java.awt.BorderLayout.CENTER);

		jPanel12.setPreferredSize(new java.awt.Dimension(150, 10));
		jPanel12.setLayout(new java.awt.BorderLayout());
		jPanel12.add(jXTaskPaneContainer1, java.awt.BorderLayout.PAGE_START);

		getContentPane().add(jPanel12, java.awt.BorderLayout.WEST);

		java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit()
				.getScreenSize();
		setBounds((screenSize.width - 703) / 2, (screenSize.height - 645) / 2,
				703, 661);

	}// </editor-fold>//GEN-END:initComponents

	protected void jCustomerAddrActionPerformed(ActionEvent e) {
		if(customerInfo==null)
			return;
		try {
			CustomerAddress addr=(CustomerAddress) JObjectListFinder.newJDialog(this).showUserList(dlSales.listByParent(CustomerAddress.class,new I_ParentNode(){

				@Override
				public IKeyed getParentKey() {
					return KeyBuilder.getKey(customerInfo.getId());
				}

				@Override
				public Class getParentClass() {
					return Customer.class;
				}
				
			}));
			if(addr!=null)
				setCustomerAddr(addr);
		} catch (BasicException e1) {
			
			e1.printStackTrace();
		}
		
	}

	private void setCustomerAddr(I_AddressEntity addr) {
		customerAddr.setText(addr.getAddress());
		
	}

	private void btnDateStartActionPerformed(java.awt.event.ActionEvent evt) {
		Date date;
		try {
			date = (Date) Formats.TIMESTAMP.parseValue(jTxtStartDate.getText());
		} catch (BasicException e) {
			date = null;
		}
		date = JCalendarDialog.showCalendarTimeHours(this, date);
		if (date != null) {
			jTxtStartDate.setText(Formats.TIMESTAMP.formatValue(date));
		}
	}

	private void m_jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jButtonOKActionPerformed

		if (oType.getConsultType() == OrderType.CONSULTTYPE_TimeSliceStore&&consultID == null) {
			MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE,
					AppLocal.getIntString("message.noConsultRef"));
			msg.show(this);
			return;
		}
		oLocateion = null;
		oLocateion1 = null;
		if (oType.getLocationRefCount() == 1) {
			oLocateion = (Location) jLocation.getSelectedItem();
		} else if (oType.getLocationRefCount() == 2) {
			oLocateion = (Location) jLocation.getSelectedItem();
			oLocateion1 = (Location) jLocation1.getSelectedItem();
			if (oLocateion1 != null && oLocateion.equals(oLocateion1)) {
				MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE,
						AppLocal.getIntString("message.selectDiffLocation"));
				msg.show(this);
				return;
			}
		}

		try {
			createDate = (Date) Formats.TIMESTAMP.parseValue(jTxtStartDate
					.getText());
		} catch (BasicException e) {
			createDate = new Date();
			e.printStackTrace();
		}
		isOk = true;
		dispose();
	}// GEN-LAST:event_m_jButtonOKActionPerformed

	private void m_jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jButtonCancelActionPerformed
		dispose();
	}// GEN-LAST:event_m_jButtonCancelActionPerformed


	private void jReverseActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jReverseActionPerformed
		if(orderType == Order.ORDERBEARING_NORMAL){
		    orderType = Order.ORDERBEARING_REVERSE;
		}else{
			orderType = Order.ORDERBEARING_NORMAL;
		}
	}// GEN-LAST:event_jReverseActionPerformed

	private void jCustomerActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jCustomerActionPerformed
		JCustomerFinder customerFinder = JCustomerFinder.getCustomerFinder(
				this, dlSales);
		customerFinder.setVisible(true);
		customerInfo = customerFinder.getSelectedCustomer();
		jCustomerName.setText(customerInfo == null ? null : CustomerHelper
				.printName(customerInfo));
		if(customerInfo!=null)
		   try {
			    setCustomerAddr((I_AddressEntity) dlSales.findByStringId(Customer.class,customerInfo.getId()));
		    } catch (BasicException e) {
			    e.printStackTrace();
		     }
	}// GEN-LAST:event_jCustomerActionPerformed

	private void jSearchOrderActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jSearchOrderActionPerformed
		JOrdersFinder finder = JOrdersFinder.getOrderFinder(this, app, dlSales, dlCustomers);
		finder.setVisible(true);
		FindOrdersInfo selectedOrder = finder.getSelectedOrder();
		if (selectedOrder != null) {
			consultID = selectedOrder.getId();
			jLabel5.setText(consultID);
		}
	}// GEN-LAST:event_jSearchOrderActionPerformed

	private void jSearchTimeStoreActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jSearchTimeStoreActionPerformed
		JTimeStoreFinder finder = JTimeStoreFinder.newJDialog(this);
		try {
			TimeStore_V temp = finder.showUserList(dlSales
					.listBuildedTimeStore());
			if (temp != null)
				consultID = temp.getID();
			else
				consultID = null;
		} catch (BasicException ex) {
			new MessageInf(ex).show(this);
			consultID = null;
		}
		jLabel7.setText(consultID);
	}// GEN-LAST:event_jSearchTimeStoreActionPerformed

	private void jEditProductActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jEditProductActionPerformed

		assignProduct(JProductFinder.showMessage(this, dlSales));
	}// GEN-LAST:event_jEditProductActionPerformed

	private void jEditAttributesActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jEditAttributesActionPerformed

		if (product == null) {
			// first select the product.
			MessageInf msg = new MessageInf(MessageInf.SGN_WARNING,
					AppLocal.getIntString("message.productnotselected"));
			msg.show(this);
		} else {
			try {
				JProductAttEdit attedit = JProductAttEdit.getAttributesEditor(
						this, dlSales);
				attedit.editAttributes(product.getAttributeSetID(),
						jattributes.getText(), true);
				attedit.setVisible(true);
				if (attedit.isOK()) {
					// The user pressed OK
					this.productInstDescID = attedit.getAttributeSetInstance().getId();
					jattributes.setText(attedit.getAttributeSetInstance().getDescription());
				}
			} catch (BasicException ex) {
				MessageInf msg = new MessageInf(MessageInf.SGN_WARNING,
						AppLocal.getIntString("message.cannotfindattributes"),
						ex);
				msg.show(this);
			}
		}
	}// GEN-LAST:event_jEditAttributesActionPerformed

	private void reflushOrderTypeState() {
		jOrderTypeName.setText(oType.getName());

		String priceType = null;
		if (oType.getPriceType() == OrderType.PRICETYPE_BuyPrice)
			priceType = AppLocal
					.getIntString("list.OrderType.PRICETYPE_BuyPrice");
		else if (oType.getPriceType() == OrderType.PRICETYPE_SellPrice)
			priceType = AppLocal
					.getIntString("list.OrderType.PRICETYPE_SellPrice");
		else if (oType.getPriceType() == OrderType.PRICETYPE_CustomerPrice)
			priceType = AppLocal
					.getIntString("list.OrderType.PRICETYPE_CustomerPrice");
		else if (oType.getPriceType() == OrderType.PRICETYPE_CustomerCategoryPrice)
			priceType = AppLocal
					.getIntString("list.OrderType.PRICETYPE_CustomerCategoryPrice");
		else if (oType.getPriceType() == OrderType.PRICETYPE_WholesalePrice)
			priceType = AppLocal
					.getIntString("list.OrderType.PRICETYPE_WholesalePrice");
		else if (oType.getPriceType() == OrderType.PRICETYPE_WholesaleCustomerCategoryPrice)
			priceType = AppLocal
					.getIntString("list.OrderType.PRICETYPE_WholesaleCustomerCategoryPrice");

		jPriceTypeName.setText(priceType);
		jChangePrice.setSelected(oType.isChangePrice());

		jFundIn.setSelected(OrderType.FUNDTYPE_In == oType.getFundType());
		jFundNoChange.setSelected(OrderType.FUNDTYPE_NoChange == oType
				.getFundType());
		jFundOut.setSelected(OrderType.FUNDTYPE_Out == oType.getFundType());

		int loctionCount = oType.getLocationRefCount();
		switch (loctionCount) {
		case 0:
			jLocation.setEnabled(false);
			jLocation1.setEnabled(false);

			jLocation_type.setText(AppLocal
					.getIntString("list.OrderType.STORE_NoChange"));
			jLocation1_type.setText(AppLocal
					.getIntString("list.OrderType.STORE_NoChange"));
			break;
		case 1:
			jLocation.setEnabled(true);
			jLocation1.setEnabled(false);

			if (oType.getInOutType() == OrderType.STORE_In
					|| oType.getInOutType() == OrderType.STORE_BalanceIn)
				jLocation_type.setText(AppLocal
						.getIntString("list.OrderType.STORE_In"));
			else
				jLocation_type.setText(AppLocal
						.getIntString("list.OrderType.STORE_Out"));
			jLocation1_type.setText(AppLocal
					.getIntString("list.OrderType.STORE_NoChange"));
			break;
		case 2:
			jLocation.setEnabled(true);
			jLocation1.setEnabled(true);

			if (oType.getInOutType() == OrderType.STORE_First_In_Second_Out) {
				jLocation_type.setText(AppLocal
						.getIntString("list.OrderType.STORE_In"));
				jLocation1_type.setText(AppLocal
						.getIntString("list.OrderType.STORE_Out"));
			} else {
				jLocation_type.setText(AppLocal
						.getIntString("list.OrderType.STORE_Out"));
				jLocation_type.setText(AppLocal
						.getIntString("list.OrderType.STORE_In"));
			}
			break;
		}
		cbDeliverType.setSelectedItem(null);
	    cbDeliverTypeDesc.setText(null);
	    cbDeliverType.setEnabled(false);
	    cbDeliverTypeDesc.setEditable(false);
		if(loctionCount>0){
			jLocation.setSelectedItem(app.getDefineLocation());
			cbDeliverType.setEnabled(true);
			cbDeliverType.setSelectedItem(AppLocal
					.getIntString("list.DeliverType.door-to-door"));
		    cbDeliverTypeDesc.setEditable(true);
		}
		
		jSearchOrder.setEnabled(false);
		jSearchTimeStore.setEnabled(false);
		consultID = null;
		jLabel5.setText(null);
		jLabel7.setText(null);
		if (oType.getConsultType() == OrderType.CONSULTTYPE_Order) {
			jSearchOrder.setEnabled(true);
		}
		if (oType.getConsultType() == OrderType.CONSULTTYPE_TimeSliceStore) {
			jSearchTimeStore.setEnabled(true);
		}
		product = null;
		productInstDescID = null;
		jproduct.setText(null);
		jattributes.setText(null);
		if (oType.isProductConsult()) {
			jEditProduct.setEnabled(true);
			jEditAttributes.setEnabled(true);
		} else {
			jEditProduct.setEnabled(false);
			jEditAttributes.setEnabled(false);
		}

		if (app.isCustomerView()) {
			jSearchOrder.setEnabled(false);
			jCustomer.setEnabled(false);
			customerInfo = app.getCustomerInfo();
			jCustomerName.setText(CustomerHelper.printName(customerInfo));
		}
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JCheckBox jChangePrice;
	private javax.swing.JButton jCustomer;
	private javax.swing.JLabel jCustomerName;
	private javax.swing.JButton jEditAttributes;
	private javax.swing.JButton jEditProduct;
	private javax.swing.JRadioButton jFundIn;
	private javax.swing.JRadioButton jFundNoChange;
	private javax.swing.JRadioButton jFundOut;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel10;
	private javax.swing.JLabel jLabel11;
	private javax.swing.JLabel jLabel12;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JLabel jLabel9;
	private javax.swing.JComboBox jLocation;
	private javax.swing.JComboBox jLocation1;
	private javax.swing.JTextField jLocation1_type;
	private javax.swing.JTextField jLocation_type;
	private javax.swing.JTextField jOrderTypeName;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel10;
	private javax.swing.JPanel jPanel11;
	private javax.swing.JPanel jPanel12;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel3;
	private javax.swing.JPanel jPanel4;
	private javax.swing.JPanel jPanel6;
	private javax.swing.JPanel jPanel7;
	private javax.swing.JPanel jPanel8;
	private javax.swing.JPanel jPanel9;
	private javax.swing.JCheckBox jReverse;
	private javax.swing.JButton jSearchOrder;
	private javax.swing.JButton jSearchTimeStore;
	private javax.swing.JTextField jTextField1;
	private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer1;
	private javax.swing.JTextField jattributes;
	private javax.swing.JComboBox jcboUser;
	private javax.swing.JTextField jproduct;
	private javax.swing.JButton m_jButtonCancel;
	private javax.swing.JButton m_jButtonOK;
	private javax.swing.JTextField jTxtStartDate;
	private JTextField customerAddr;
	private JLabel label;
	private JTextField cbDeliverTypeDesc;
	private JComboBox cbDeliverType;

	// End of variables declaration//GEN-END:variables

	private void assignProduct(Product prod) {
		product = prod;
		if (product == null) {
			jproduct.setText(null);
		} else {
			jproduct.setText(product.getReference() + " - " + product.getName());
		}
	}
	

	private class OrderTypeSelectedAction extends AbstractAction {
		OrderType oType1;

		public OrderTypeSelectedAction(OrderType oType) {
			super(oType.getName());
			this.oType1 = oType;
		}

		public OrderType getoType() {
			return oType1;
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			oType = oType1;
			reflushOrderTypeState();
		}
	}

	public UserInfo getReferencePerson() {
		return (UserInfo) m_ReferencePersonListModel.getSelectedItem();
	}

	public String getProdcutID() {
		if (product == null)
			return null;
		return product.getID();
	}

	public String getProductInstDescID() {
		return productInstDescID;
	}

	public String getProdcutName() {
		String name = jproduct.getText();
		if (productInstDescID != null)
			name += jattributes.getText();
		return name;
	}

	public Date getCreateDate() {
		return createDate;
	}
	
	public String getCustomerAddr(){
		return customerAddr.getText();
	}
	
	public String getDeliverType(){
		return (String)cbDeliverType.getSelectedItem();
	}
	
	public String getDeliverTypeDesc(){
		return cbDeliverTypeDesc.getText();
	}

	
}
